package com.example.administrator.xueya;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private List<Integer> list;
    private Button left;
    private Button right;
    private TextView date;
    private String[] dates;
    private StringBuffer datestring;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        left = (Button) findViewById(R.id.leftbtn);
        right = (Button) findViewById(R.id.rightbtn);
        date = (TextView) findViewById(R.id.date);
        left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //往前移动一周

            }
        });
        right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
        String da = format.format(new Date());
        SimpleDateFormat weekformat = new SimpleDateFormat("EEEE");
        String week = weekformat.format(new Date());
        dates = da.split("/");

        switch (week) {
            case "星期一":
                datestring = getDate(1);
                break;
            case "星期二":
                datestring = getDate(2);
                break;
            case "星期三":
                datestring = getDate(3);
                break;
            case "星期四":
                datestring = getDate(4);
                break;
            case "星期五":
                datestring = getDate(5);
                break;
            case "星期六":
                datestring = getDate(6);
                break;
            case "星期日":
                datestring = getDate(7);
                break;
        }
        date.setText(datestring);
    }
    private StringBuffer getDate(int week){
        StringBuffer start = new StringBuffer();
        StringBuffer end = new StringBuffer();
        StringBuffer total = new StringBuffer();
        start.append(dates[0]).append("/").append(dates[1]).append("/").append(Integer.decode(dates[2]) - (week-1));
        end.append(dates[0]).append("/").append(dates[1]).append("/").append(Integer.decode(dates[2]) + (7-week));
        total.append(start).append("-").append(end);
        return total;
    }
}
